﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 剧情设计器2._0
{
    public partial class RelationshipEditor : Form
    {
        Relationship relationship;
        public RelationshipEditor(Relationship r)
        {
            relationship = r;
            InitializeComponent();
        }

        void UpdateDisplay()
        {
            comboBox_active.BeginUpdate();
            comboBox_passive.BeginUpdate();
            comboBox_active.Items.Clear();
            comboBox_passive.Items.Clear();
            foreach(Character c in Common.characters)
            {
                comboBox_active.Items.Add(c.name);
                comboBox_passive.Items.Add(c.name);
            }
            comboBox_active.EndUpdate();
            comboBox_passive.EndUpdate();
            comboBox_active.Text = relationship.active_character;
            comboBox_passive.Text = relationship.passive_character;
            comboBox_relationship.Text = relationship.relationship;
            checkBox_build.Checked = relationship.build;
            comboBox_relationship.BeginUpdate();
            comboBox_relationship.Items.Clear();
            foreach (string type in Common.relationship_types)
            {
                comboBox_relationship.Items.Add(type);
            }
            comboBox_relationship.EndUpdate();

            edit_description.Text = relationship.description;
        }

        private void RelationshipEditor_Load(object sender, EventArgs e)
        {
            UpdateDisplay();
        }

        private void btn_ok_Click(object sender, EventArgs e)
        {
            relationship.active_character = comboBox_active.Text;
            relationship.passive_character = comboBox_passive.Text;
            relationship.relationship = comboBox_relationship.Text;
            relationship.build = checkBox_build.Checked;
            relationship.description = edit_description.Text;

            if(!Common.inList(comboBox_relationship.Text, Common.relationship_types) && comboBox_relationship.Text != "")
            {
                if (MessageBox.Show(string.Format("发现一个未定义的关系类型：{0}\n是否将其添加到关系类型预设中?", comboBox_relationship.Text), "发现新关系", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    Common.relationship_types.Add(comboBox_relationship.Text);
                }
            }
            Close();
        }
    }
}
